import Vue from 'vue'
import Router from 'vue-router'
import Index from './pages/index'
import Login from './pages/login'
import Course from './pages/course/list'
import Quetion from './pages/course/question'
import CourseEdit from './pages/course/edit'
import CourseVideoList from './pages/course/video-list'
import Works from './pages/works/list'
import WorksEdit from './pages/works/edit'

//注册路由
Vue.use(Router)
var router = new Router({
	routes:[
		{path: '/', component: Index},
		{path: '/login', component: Login},
		{path: '/course/list', component: Course},
		{path: '/course/video/list', component: CourseVideoList},
		{path: '/course/question', component: Quetion},
		{path: '/course/edit', component: CourseEdit},
		{path: '/works/list', component: Works},
		{path: '/works/edit', component: WorksEdit},
	],
})

//导航守卫
router.beforeEach((to, from, next) => {
	//除了unless页面，其它页面都需要携带左侧导航父ID和子ID
	var unless = ['/login', '/']
	if(!to.query.navpid && unless.indexOf(to.path) === -1 && from.query.navpid){
		next({
			path: to.path,
			query: Object.assign(from.query, to.query)
		})
	}else{
		next()
	}
})

export default router